<?php
class textarea extends validatableinput {
	public $content;
	
	public function __construct($content = ''){
		$this->setContent($content);		
		$this->validAttributes[] = 'name';
		$this->validAttributes[] = 'cols';
		$this->validAttributes[] = 'rows';
		$this->validAttributes[] = 'disabled';
		$this->validAttributes[] = 'readonly';		
		$this->tag = 'textarea';
	}
		
	public function __toString(){
		//opening tag
		$this->html = "<";
		
		//add html tag for this type of widget
		$this->html .= $this->tag;
		
		foreach ( $this->attributes as $key => $value){
			if ( ! empty($value) || strlen($value)){
				$this->html .= ' ' . $key . '="' . $value . '"';
			}
		}
		$this->html .= '>';
		$this->html .= $this->content;
		//add closing tag
		$this->html .=  "</";
		$this->html .= $this->tag;
		$this->html .= ">";
		return $this->html;
	}

	public function setContent($content){
		if ( (is_null($content))){
			$this->content = '';
		} elseif ( is_scalar($content)){
			if (strlen($content) == 0 ){
				$this->content = '';
			} else {
				$this->content = $content;
			}
		} elseif ( is_array($content)){
			$this->content = join(" ", $value);
		} elseif ( $content instanceof htmlwidget){
			$this->content = $content->getHtml();
		} elseif (is_object($value) && method_exists($content , '__toString')){
			$this->content = $value->__toString();
		} else {
			$this->content = '';
		}
	}
	
	public function appendContent($content){
		if ( (is_null($content))){
			//do nothing
		} elseif ( is_scalar($content)){
			if (strlen($content) == 0 ){
				//do nothing
			} else {
				$this->content .= $content;
			}
		} elseif ( is_array($content)){
			$this->content .= join(" ", $value);
		} elseif ( $content instanceof htmlwidget){
			$this->content .= $content->getHtml();
		} elseif (is_object($value) && method_exists($content , '__toString')){
			$this->content .= $value->__toString();
		} else {
			//do nothing
		}
	}
	
	public function prependContent($content){
		$temp = $this->content;
		$this->setContent($content);
		$this->appendContent($temp);
	}
	
	public function getcontent(){
		return $this->content;
	}

	public function clear(){
		parent::clear();
		$this->content = '';
	}
	
	public function setrows($numrows){
		$this->attributes['rows'] = $numrows;
	}

	public function rows($numrows){
		$this->attributes['rows'] = $numrows;
	}	
	
	public function setcols($numcols){
		$this->attributes['cols'] = $numcols;
	}	
	
	public function cols($numcols){
		$this->attributes['cols'] = $numcols;
	}	
	
	public function getcols(){
		return $this->attributes['cols'];
	}
	
	public function setdisabled($value){
		$this->attributes['disabled'] = $value;
	}
	
	public function disable(){
		$this->attributes['disabled'] = 'true';
	}	
	
	public function setreadonly($value){
		$this->attributes['readonly'] = $value;
	}
	
	public function readonly(){
		$this->attributes['readonly'] = 'true';
	}
}
?>